<?php
class Plugin_NavigationSwitch extends Zend_Controller_Plugin_Abstract {
    
    protected $_layout = null;

    protected $_auth = null;

    protected $_acl = null;
    
    public function __construct($layout, $auth, $acl) {
        $this->_layout = $layout;
        $this->_auth   = $auth;
        $this->_acl    = $acl;
    }

    /**
     * @param Zend_Controller_Request_Abstract $request
     *
     * modulspezifische navigation wird gesetzt
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request) {

        $role       = null;
        $view       = $this->_layout->getView();
        $module     = $request->getModuleName();
        $navigation = $module;

        $container = new Zend_Navigation(new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation/'.$navigation.'.xml', 'nav'));

        if(!isset($container)){
            $container = null;
        }

        $this->_auth->setStorage(new Zend_Auth_Storage_Session($module));
        if(isset($this->_auth->getStorage()->read()->role)){
            $role = $this->_auth->getStorage()->read()->role;
        }

        $view->navigation($container)
            ->setTranslator(Zend_Registry::get('Zend_Translate'))
            ->setAcl($this->_acl)
            ->setRole($role);
    }
}